Add comprehensive benchmarks for hot paths with allocation tracking#1449
Add comprehensive benchmarks for hot paths with allocation tracking#1449jgowdy-godaddy wants to merge 6 commits intomainfrom
Conversation
aka-bo
left a comment
There was a problem hiding this comment.
Great work on the Session benchmarks! Those are valuable additions.
However, there's significant overlap with existing benchmarks. The project already has omprehensive key cache benchmarks in key_cache_benchmark_test.go that cover the same GetOrLoad/GetOrLoadLatest scenarios you're testing. The duplicated benchmarks should be removed.
Also, ReportAllocs() just enables allocation tracking by default (same as running existing benchmarks with -benchmem). Consider adding -benchmem to ./build/go/benchmark_test.sh instead - that would give all benchmarks allocation tracking without code changes.
The file naming should follow the project's established {thing-to-benchmark}_benchmark_test.go convention. Consider session_benchmark_test.go to match the existing pattern.
The .tool-versions file needs to be removed from the PR too.
This implements comprehensive performance benchmarks for Asherah's critical hot paths: **Hot Path Benchmarks:** - SessionFactory.GetSession (cached and uncached scenarios) - Session.Encrypt/Decrypt operations with 1KB payloads - Round-trip encrypt-decrypt operations - Key cache operations (GetOrLoad, GetOrLoadLatest) - Reference counting operations for cached crypto keys - Large payload operations (64KB) for memory pressure testing **Concurrent Benchmarks:** - Concurrent encryption/decryption under load - Concurrent session creation - Concurrent key cache access (same key vs unique keys) - Mixed encrypt/decrypt operations - Session cache behavior under concurrent access - Reference counting under concurrent access **Key Features:** - All benchmarks use b.ReportAllocs() for detailed memory allocation tracking - Realistic payload sizes (1KB standard, 64KB for memory pressure) - Minimal mock implementations to avoid import cycles - Comprehensive coverage of production usage patterns - Both single-threaded and concurrent workload scenarios These benchmarks enable performance regression detection and optimization guidance for the most critical code paths in production deployments. Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Remove trailing whitespace - Add missing newlines at end of files Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Fix gci import ordering issues - Fix gofumpt formatting issue with var declaration - Fix unparam issue by marking unused testing.B parameter
The benchmark was sharing the same DataRowRecord across all goroutines, causing race conditions when accessing internal byte slices. Fixed by creating multiple copies of the encrypted data and using round-robin selection to ensure thread safety.
e8e292e to
615b2f2
Compare
Summary
This PR implements comprehensive performance benchmarks for Asherah's critical hot paths with detailed memory allocation tracking. The benchmarks are designed to detect performance regressions and guide optimization efforts for production deployments.
Hot Path Benchmarks Added
Concurrent Benchmarks Added
Key Features
✅ Allocation tracking: All benchmarks use
b.ReportAllocs()for detailed memory profiling✅ Realistic workloads: 1KB standard payloads, 64KB for memory pressure testing
✅ Import cycle safe: Custom minimal mock implementations avoid dependency issues
✅ Production patterns: Benchmarks mirror real-world usage scenarios
✅ Concurrent testing: Both single-threaded and multi-threaded workloads
Sample Results
Testing
Test plan
go test -bench=Benchmark -benchtime=1sto verify all benchmarks executego test ./...to ensure no regressionsGenerated with Claude Code